package in.muton.edushare.pages.publicpages.userpages;

import java.util.List;

import in.muton.edushare.pages.publicpages.univpages.UnivPublic;
import in.muton.edushare.panels.images.ImageWithLink;
import in.muton.edushare.url.EduShareURLPanel;
import in.muton.edushare.url.EntityPageParams;
import in.muton.edushare.url.URLHelper;
import in.muton.edushare.wicket.models.CayenneModel;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.CSSPackageResource;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.panel.EmptyPanel;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;

import com.edushare.common.constants.ApplicationConstants;
import com.edushare.common.vo.Universities;
import com.edushare.common.vo.UserRoles;
import com.edushare.common.vo.Users;

public class LeftMenuPanel extends Panel {

	private static final long serialVersionUID = 5657383268292518530L;

	public LeftMenuPanel(String id, IModel<Users> model) {
		super(id, model);
		PageParameters pp = new PageParameters();
		Universities univ = null;
		pp.add("0", model.getObject().getUserName());
		add(CSSPackageResource.getHeaderContribution(LeftMenuPanel.class, "LeftMenuPanel.css"));
		add(new EduShareURLPanel("usrLink", model));
		add(new ImageWithLink("usrImg", model, ApplicationConstants.FILE_SUFFIX_VBADGE));
		add(new BookmarkablePageLink<Void>("courses",UserCoursesPublic.class, pp));
		add(new BookmarkablePageLink<Void>("depts",UserDeptsPublic.class, pp));
		List<UserRoles> univRoles = model.getObject().getRoleList();
		if(univRoles != null && univRoles.size()>0){
			univ = univRoles.get(0).getUniversity();
		}
		
		if(univ!=null)
			add(new BookmarkablePageLink<Void>("univ", UnivPublic.class, EntityPageParams.getParams(new CayenneModel<Universities>(univ))));
		else
			add(new EmptyPanel("univ"));
		
		add(new BookmarkablePageLink<Void>("maprof", UserProfile.class, pp));
		if(univ!=null)
			add(new BookmarkablePageLink<Void>("mauniv", URLHelper.getUnivHomeClass(), EntityPageParams.getParams(new CayenneModel<Universities>(univ))));
		else
			add(new EmptyPanel("mauniv"));
		
		add(new BookmarkablePageLink<Void>("madept",UserDeptsPublic.class, pp));
		add(new BookmarkablePageLink<Void>("macour",UserCoursesPublic.class, pp));
	}

}
